<template>
    <base-panel>
        <top-simple-search @addFun="toAdd" @searchFun="toSearch" >
            <el-form-item label="" prop="comset">
                <dept-select-tree style="width: 200px" v-model="formData.comset" :disable-branch-nodes="true" placeholder="请选择栏目名称"  v-bind="$attrs" dept-type="other" :all-dept-list="comsetList" v-if="loading"></dept-select-tree>
            </el-form-item>
        </top-simple-search>
        <simple-table ref="myTable">
            <el-table-column align="left" prop="name" label="应用名称"/>
            <el-table-column align="left" prop="comset_name" label="栏目名称"/>
            <el-table-column align="left" prop="link" label="链接名称"/>
            <el-table-column align="left" prop="workflow_name" label="工作流"/>
            <el-table-column align="left" prop="client" label="显示终端" width="120" :formatter="clientFormatter"/>
<!--            <el-table-column align="left" prop="no_order" label="排序" width="120"/>-->
            <el-table-column align="left" prop="status" label="状态" width="120" :formatter="statusFormatter"/>
            <el-table-column align="left" label="操作" width="200">
                <template slot-scope="{row}">
                    <detail-button @click="toDetail(row)"></detail-button>
                    <edit-button @click="toEdit(row)"></edit-button>
                    <delete-button @click="toDelete(row.id)"></delete-button>
                </template>
            </el-table-column>
        </simple-table>
        <detail-dialog :visible.sync="visible" v-if="visible" @reloadList="getList" :row="currRow" :disabled="disabled" :parentList="list"></detail-dialog>
    </base-panel>

</template>
<script>
    import category from "@/api/systemManagement/useful/category/index"
    import DetailDialog from "./DetailDialog";
    import simpleTable from "@/mixins/SimpleTable";
    import XEUtils from "xe-utils";
    import DeptSelectTree from "@/components/Common/DeptSelectTree";
    export default {
        mixins:[simpleTable],
        components: {DeptSelectTree, DetailDialog},
        data(){
            return{
                listVisible:false,
                list:[],
                formData:{
                    comset:undefined,
                    search_value:undefined
                },
                loading:false
            }
        },
        created() {
            this.getCategoryList()
        },
        methods:{
            getCategoryList(){
                category.getCategorySimple().then(res=>{
                    this.comsetList= res.data;
                    this.loading = true
                })
            },
            clientFormatter(row){
                return row.client?"手机":"PC"
            },
            statusFormatter(row){
                return row.status?"启用":"禁用"
            },
            toSearch(params){
                this.formData.search_value=params;
                this.getList(this.formData)
            },
            dataFormatter(data){
                this.list = XEUtils.toArrayTree(data, {
                    parentKey: 'parent',
                    key: 'id',
                    children: 'children'
                });
                return this.list
            },
        }
    }
</script>
